//
//  cardChooseView.m
//  haolyy
//
//  Created by ourslook on 15/7/29.
//  Copyright (c) 2015年 haolyy. All rights reserved.
//

#import "cardChooseView.h"
#import "DataModel.h"

@implementation cardChooseView


-(void)awakeFromNib{
    _cardList = [NSMutableArray new];
    
    _pickerView.delegate = self;
    _pickerView.dataSource = self;
    //_cardList = single.cardList;
}

-(void)setCardList:(NSMutableArray *)cardList{
    [_cardList removeAllObjects];
    [_cardList addObjectsFromArray:cardList];
    [_pickerView reloadAllComponents];
}

#pragma mark - pickerViewDelegate pickerViewDatasource
//有多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

//每列有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return _cardList.count;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    SelectTypeBean * cardBean = [_cardList objectAtIndex:row];
    
    NSString *str = cardBean.name;

    return str;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if ([_delegate respondsToSelector:@selector(cardChooseView:didSelectRow:withCardBean:)]) {
        [_delegate cardChooseView:pickerView didSelectRow:row withCardBean:_cardList[row]];
    }
}

- (IBAction)click_cancel:(id)sender {
    if ([_delegate respondsToSelector:@selector(cancel)]) {
        [_delegate cancel];
    }
}

- (IBAction)click_ensure:(id)sender {
    //确认当前picker被选中的行数
    NSInteger row = [_pickerView selectedRowInComponent:0];
    if ([_delegate respondsToSelector:@selector(chooseCard:)]) {
        [_delegate chooseCard:_cardList[row]];
    }
}

@end
